View Javadoc

1   /*
2    * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, are permitted under the terms of either of the following
6    * Open Source licenses:
7    *
8    * The GNU General Public License, version 2, or any later version, as
9    * published by the Free Software Foundation
10   * (http://www.fsf.org/copyleft/gpl.html);
11   *
12   *  or
13   *
14   * The Semiotek Public License (http://webmacro.org/LICENSE.)
15   *
16   * This software is provided "as is", with NO WARRANTY, not even the
17   * implied warranties of fitness to purpose, or merchantability. You
18   * assume all risks and liabilities associated with its use.
19   *
20   * See www.webmacro.org for more information on the WebMacro project.
21   */
22  
23  
24  package org.webmacro.engine;
25  
26  import org.webmacro.Context;
27  import org.webmacro.Macro;
28  import org.webmacro.PropertyException;
29  
30  
31  /***
32   * Operate on bean properties of an existing macro; used when a Macro
33   * is passed as an argument to a macro
34   * @author Brian Goetz
35   * @since 1.1
36   */
37  public class MacroPropertyVariable extends Variable
38  {
39  
40      private Macro value;
41  
42      /***
43       * No special initialization
44       */
45      MacroPropertyVariable (Macro value, Object names[])
46      {
47          super(names);
48          this.value = value;
49      }
50  
51      /***
52       * Look up my value in the corresponding Map, possibly using introspection,
53       * and return it
54       * @exception PropertyException If the property does not exist
55       */
56      public final Object getValue (Context context)
57              throws PropertyException
58      {
59          Object v = value.evaluate(context);
60          if (v == null)
61              throw new PropertyException.NullValueException(_names[0].toString());
62          else
63              return context.getBroker()
64                      ._propertyOperators.getProperty(context, v, _names, 1);
65      }
66  
67      /***
68       * Look up my the value of this variable in the specified Map, possibly
69       * using introspection, and set it to the supplied value.
70       * @exception PropertyException If the property does not exist
71       */
72      public final void setValue (Context context, Object newValue)
73              throws PropertyException
74      {
75          throw new PropertyException("Cannot set properties of a constant");
76      }
77  
78      /***
79       * Return a string representation naming the variable for
80       * debugging purposes.
81       */
82      public final String toString ()
83      {
84          return "macro-property:" + getVariableName();
85      }
86  
87  }